<template>
  <div class="mod-config">

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column prop="billId" label="销售单号" width="180">
            <template slot-scope="scope">
              <el-button type="text" @click="checkDetailByOrder(scope.row.billId)">{{scope.row.billId}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="deptName" label="销售门店"></el-table-column>
          <el-table-column prop="optometryBillId" label="验光单号" width="180"></el-table-column>
          <el-table-column prop="saleType" label="销售类型" :formatter="saleTypeFormatter" width="80"></el-table-column>
          <el-table-column prop="checkFlag" label="处方类型" :formatter="checkFlagFormatter" width="80"></el-table-column>
          <el-table-column prop="salerUsername" label="销售人员" width="80"></el-table-column>
          <el-table-column prop="originalPrice" label="原价合计" width="100"></el-table-column>
          <el-table-column prop="discountPrice" label="优惠金额" width="100"></el-table-column>
          <el-table-column prop="receivablePrice" label="应收金额" width="100"></el-table-column>
          <el-table-column prop="refundFlag" label="退货状态" :formatter="refundFlagFormatter" width="80"></el-table-column>
          <el-table-column prop="payTime" label="收款日期" width="140"></el-table-column>
          </el-table>
      </div>
      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next"
        ></el-pagination>
      </div>
      <order-info v-if="infoVisible" ref="infoDialog"></order-info>
  </div>
</template>

<script>
import { getSaleInfoPage } from "@/api/eims/customer.js";
import OrderInfo from '@/views/eims/optician/glassesinfo/detail'
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      infoVisible: false,
      dataForm: {
        key: ""
      },
      dataList: [],
      searchShow: true,
      pageIndex: 1,
      pageSize: 100,
      totalPage: 0,
      dataListLoading: false
    };
  },
  components: {
    OrderInfo
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  methods: {
    // 初始化数据
    init(customerId,customerCard) {
      this.customerId = customerId
      this.customerCard = customerCard
      this.$nextTick(() => {
        this.getDataList()
      })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }
      let params2 = {
        customerId : this.customerId,
        customerCard: this.customerCard
      }
      getSaleInfoPage(Object.assign(params1, params2)).then(response => {
        if(response.data.code == '0'){
          this.dataList = response.data.data.records
          this.totalPage = response.data.data.total
        }else{
          this.$message.error(response.data.msg)
        }
        this.dataListLoading = false;
      });

    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    saleTypeFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return '隐形订做'
          break
        case "2":
          return '框镜订做'
          break
        case "3":
          return '隐形成品'
          break
        case "4":
          return '框镜成品'
          break
        case "5":
          return '辅料'
          break
      }
    },
    checkFlagFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return '内方'
          break
        case "0":
          return '辅料'
          break
      }
    },
    refundFlagFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return '已退货'
          break
        case "0":
          return '未退货'
          break
      }
    },
    //  查看配镜单详情
    checkDetailByOrder(order){
      this.infoVisible = true;
      this.$nextTick(() => {
        this.$refs.infoDialog.init('',order,'配镜单详情');
      });
    },
  }
};
</script>
